<template>
    <view>
		<view v-if="dangan_ts != ''" class="radius bg-white padding-main cr-main"></view>
		<block v-if="data_list_loding_status != 1">
			<scroll-view :scroll-y="true" class="scroll-box" @scrolltolower="scroll_lower" lower-threshold="30">
				<view v-if="data_list.length > 0" class="padding-horizontal-main padding-top-main">
					<view v-for="(item, index) in data_list" :key="index" class="padding-main border-radius-main bg-white oh spacing-mb">
						<view class="br-b-dashed oh padding-bottom-main">
							<text class="fw-b">{{item.form_title}}</text>
							<text class="fr cr-base">{{item.add_time_time}}</text>
						</view>
		   
						<view v-if="(item.item || null) != null" class="margin-top-main padding-top-main">
							<view v-for="(item2, index2) in item.item" :key="index2" class="spacing-mb">
								<text class="cr-white padding-top-xs padding-bottom-xs padding-left padding-right round margin-right-sm" :style="'background:'+diytheme.main_color+';'">{{index2+1}}</text>
								<text class="cr-black">{{item2.title}}:</text>
								<view class="liuyancontent cr-grey">
									<block v-if="item2.type_id == '9' || item2.type_id == '10'">
										<view v-for="(item3, index3) in item2.picurl" :key="index3" class="">
											<block v-if="item2.file_type == 'images'">
												<image :src="item3.images" @tap="upload_show_event" :data-index="index" :data-index2="index2" :data-index3="index3" mode="aspectFill" class="padding-xs dis-block"></image>
											</block>
											<block v-else-if="item2.file_type == 'video'">
												<video :src="item3.images" :show-center-play-btn="true" :controls="false" :show-play-btn="false" :enable-progress-gesture="false" :show-fullscreen-btn="false"></video>
											</block>
											<block v-else>
												<view class="wendangbox">{{item3.images_name}}</view>
											</block>
										</view>
										<view class="cl"></view>
									</block>
									<block v-else>
										<mp-html :content="item2.content_value" />
									</block>
								</view>
								<view class="cl"></view>
							</view>
						</view>
						<!--<view v-if="item.order_id != 0" class="item-operation tr br-t padding-vertical-main">
							<button v-if="item.order_id != 0" class="round bg-white cr-main br-main" type="default" size="mini" @tap="url_event" :data-value="'/pages/user-order-detail/user-order-detail?id='+item.order_id" hover-class="none">定制单详情</button>
						</view>-->
					</view>
				</view>
				<view v-else>
					<!-- 提示信息 -->
					<component-no-data :propStatus="data_list_loding_status"></component-no-data>
				</view>

				<!-- 结尾 -->
				<component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
			</scroll-view>
		</block>
        <!-- 新增入口 -->
        <navigator v-if="form_id>0" :url="'/pages/fcc/formplus/dangan-form/dangan-form?id='+form_id" hover-class="none">
            <view class="answer-add-submit cr-white round tc" :style="'background:'+diytheme.main_color+';'">+</view>
        </navigator>
		<view class="answer-add-submit answer-add-submit-2 cr-white round tc" :style="'background:'+diytheme.main_color+';'" @tap="url_event" data-value="/pages/user/user">
			<uni-icons type="back" size="30" color="#ffffff"></uni-icons>
		</view>
		<!--<view class="bottom-fixed padding-main" v-if="form_id>0">
			<navigator :url="'/pages/fcc/formplus/dangan-form/dangan-form?id='+form_id" hover-class="none">
				<button class="cr-white round text-size" :style="'background:'+diytheme.main_color+';border:1px solid '+diytheme.main_color+';'" type="default" hover-class="none">去提交信息</button>
			</navigator>
		</view>-->

		<!-- #ifdef APP-PLUS -->
		<yk-authpup ref="authpup" type="top" @changeAuth="changeAuth" :permissionID="permissionID"></yk-authpup>
		<!-- #endif -->
    </view>
</template>
<script>
    const app = getApp();
    import componentNoData from "@/components/no-data/no-data";
    import componentBottomLine from "@/components/bottom-line/bottom-line";
	import {system_base_info} from "@/common/js/common/common";
	// #ifdef APP-PLUS
	import ykAuthpup from "@/components/yk-authpup/yk-authpup";
	// #endif
    export default {
        data() {
            return {
				params: null,
                data_list: [],
                data_total: 0,
                data_page_total: 0,
                data_page: 1,
                data_list_loding_status: 1,
                data_bottom_line_status: false,
				dangan_ts:'',
				form_id:0,
				diytheme:null,
				lang_info:null,
				permissionID:''
            };
        },

        components: {
			// #ifdef APP-PLUS
			ykAuthpup,
			// #endif
            componentNoData,
            componentBottomLine
        },
        props: {},

        onLoad(params) {
            //params['id'] = 5;
			var form_id = params.id || 0;
            this.setData({
                params: params,
				form_id:form_id
            });
        },

        onShow() {
			app.globalData.page_event_onshow_handle();
            this.init();
            
            // 分享菜单处理
            app.globalData.page_share_handle();
        },

        // 下拉刷新
        onPullDownRefresh() {
            this.setData({
                data_page: 1
            });
            this.get_data_list(1);
        },

        methods: {
			// 加载之前
			init() {
				// 先获取语言基础信息
				system_base_info()
				.then(data=>{
					this.init_before(data)
					.then(()=>{
						this.init_real();
					});
				});
			},
			
			// 设置本页参数
			init_before(data){
				var self = this;
				return new Promise((resolve, reject) => {
					self.setData({
						lang_info: data.system_lang_info,
						diytheme: data.diytheme,
					});
					/*uni.setNavigationBarTitle({
					    title: data.index_page_title
					});*/
					resolve();
				});
			},
            init_real() {
                var user = app.globalData.get_user_info(this, "init");
                if (user != false) {
					// 获取数据
					this.get_data_list();
                } else {
                    this.setData({
                        data_list_loding_status: 0,
                        data_bottom_line_status: false
                    });
                }
            },
			// 上传图片预览
			upload_show_event(e) {
			    var index = e.currentTarget.dataset.index;
			    var index2 = e.currentTarget.dataset.index2;
				var index3 = e.currentTarget.dataset.index3;
				var temp = this.data_list[index]['item'][index2]['picurl'];
				var temp_img = [];
				for(var i=0;i<temp.length;i++)
				{
					temp_img.push(temp[i]['images']);
				}
			    
				if(app.globalData.is_android())
				{
					var self = this;
					uni.previewImage({
					    current: temp_img[index3],
					    urls: temp_img,
						longPressActions: {
							itemList: [self.$t('fengcheche.fcctips.t9')],
							success: function(data) {
								uni.closePreviewImage();
								self.permissionID = 'WRITE_EXTERNAL_STORAGE';
								setTimeout(()=>{
									self.$refs['authpup'].open(temp_img[index3]);
								},500);
							},
							fail: function(err) {
								console.log(err.errMsg);
							}
						}
					});
				}else{
					uni.previewImage({
					    current: temp_img[index3],
					    urls: temp_img
					});
				}
			},
			// #ifdef APP-PLUS
			//用户授权权限后的回调
			changeAuth(e){
				if(this.permissionID == 'WRITE_EXTERNAL_STORAGE')
				{
					// 直接下载
					app.globalData.save_image_by_url(e);
				}
			},
			// #endif
            get_data_list(is_mandatory) {
                // 分页是否还有数据
                if ((is_mandatory || 0) == 0) {
                    if (this.data_bottom_line_status == true) {
                        uni.stopPullDownRefresh();
                        return false;
                    }
                }
                
                // 加载loding
                uni.showLoading({
                    title: this.$t('common.loading_in_text'),
                });
                this.setData({
                    data_list_loding_status: 1
                });
                
                // 获取数据
				var data = {};
				data['page'] = this.data_page;
				data['form_id'] = this.form_id;
                uni.request({
                    url: app.globalData.get_request_url("index", "index", "yxformplus"),
                    method: 'POST',
                    data: data,
                    dataType: 'json',
                    success: res => {console.log(res);
                        uni.hideLoading();
                        uni.stopPullDownRefresh();
                        if (res.data.code == 0) {
                            if (res.data.data.data.length > 0) {
                                if (this.data_page <= 1) {
                                    var temp_data_list = res.data.data.data;
                                } else {
                                    var temp_data_list = this.data_list || [];
                                    var temp_data = res.data.data.data;
                                    for (var i in temp_data) {
                                        temp_data_list.push(temp_data[i]);
                                    }
                                }
								
                                this.setData({
                                    data_list: temp_data_list,
                                    data_total: res.data.data.total,
                                    data_page_total: res.data.data.page_total,
                                    data_list_loding_status: 3,
                                    data_page: this.data_page + 1
                                });

                                // 是否还有数据
                                this.setData({
                                    data_bottom_line_status: (this.data_page > 1 && this.data_page > this.data_page_total)
                                });
                            } else {
                                this.setData({
                                    data_list_loding_status: 0
                                });
                            }
							
							var form_title = res.data.data.form_title;
							if(form_title != '')
							{
								setTimeout(function() {
								    uni.setNavigationBarTitle({
								    	title: form_title
								    });
								}, 500);
							}
                        } else {
                            this.setData({
                                data_list_loding_status: 0
                            });
                            if (app.globalData.is_login_check(res.data, this, 'get_data_list')) {
                                app.globalData.showToast(res.data.msg);
                            }
                        }
                    },
                    fail: () => {
                        uni.hideLoading();
                        uni.stopPullDownRefresh();
                        this.setData({
                            data_list_loding_status: 2
                        });
                        app.globalData.showToast(this.$t('common.internet_error_tips'));
                    }
                });
            },
			
			// url事件
			url_event(e) {
			    app.globalData.url_event(e);
			},

            // 滚动加载
            scroll_lower(e) {
                this.get_data_list();
            }
        }
    };
</script>
<style>
    @import './dangan-list.css';
</style>